#include <stdio.h>
#include <math.h>
enum boolean { false=0,true=1 } ;
int ishex(char);
long long int gethex(int);
/*** long double is %Le */
/** %lld is long long int. because that makes sense */
int main()
{

  char in=0;

  char buffer[32];
  for (int i =0; i < 15; i++)
  {
    buffer[i]=0;
  }
  
  long long int i =0;
  in=getchar();
  while(ishex(in))
    {
	 buffer[i]=gethex(in);
      printf("buffer[ %lld ]: %d \n",i,buffer[i]);
	 i++;
	 in=getchar();
    }

  long long int sum =0;
  long int base = 1;
  for (int j=i-1; j>=0; j--)
  {
    printf("sum: %lld \n",sum);
    printf("base: %ld \n",base);
    printf("buffer[ %d ]: %d \n",j,buffer[j]);
    
    sum+=base*buffer[j];
    base*=0x10;
    if (sum<0)
	 {
	   printf (" ** ! houston, we have a problem. BigNum class needed ! \n");
	   return -1;
	 }
  }
  
  printf("%lld \n",sum);
  return (0);
}

int ishex(char in)
{
  if ((in>='0') && (in<='9'))  //decimal
    return true;
  if ((in>='a') && (in<='f'))  //lowercase
    return true;
  if ((in>='A') && (in<='F'))  //uppercase
    return true;
  return false;
} 

long long int gethex(int in)
{
  if ((in>='0') && (in<='9'))  //decimal
    return in-'0';
  if ((in>='a') && (in<='f'))  //lowercase
    return in-'a'+0xa;
  if ((in>='A') && (in<='F'))  //uppercase
    return in-'A'+0xa;  
}
